1
|
|
|
function stripTrailingSlash(str: string): string { |
2
|
|
|
return str.endsWith("/") ? str.slice(0, -1) : str; |
3
|
|
|
} |
4
|
|
|
|
5
|
|
|
function isValidUrl(str: string): boolean { |
6
|
|
|
if (str.startsWith("http://") || str.startsWith("https://")) { |
7
|
|
|
try { |
8
|
|
|
const url = new URL(str); |
9
|
|
|
} catch (_) { |
10
|
|
|
return false; |
11
|
|
|
} |
12
|
|
|
return true; |
13
|
|
|
} |
14
|
|
|
return false; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
export function baseUrl(): string { |
18
|
|
|
const base = document.querySelector("meta[name='base-url']"); |
19
|
|
|
if (base !== null) { |
20
|
|
|
return stripTrailingSlash(base.getAttribute("content") ?? ""); |
21
|
|
|
} |
22
|
|
|
return ""; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
export function basePathname(): string { |
26
|
|
|
const base = baseUrl(); |
27
|
|
|
return isValidUrl(base) ? new URL(baseUrl()).pathname : ""; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
export function baseApiUrl(version = 1): string { |
31
|
|
|
return `${baseUrl()}/api/v${version}`; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @param imgFile The name of the img file, not inluding the /images/ path. |
37
|
|
|
*/ |
38
|
|
|
export function imageUrl(imgFile: string): string { |
39
|
|
|
return `${baseUrl()}/images/${imgFile}`; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Removes the base url or base pathname if the given url starts with them. |
44
|
|
|
* @param url |
45
|
|
|
*/ |
46
|
|
|
export function removeBaseUrl(url: string): string { |
47
|
|
|
const base = baseUrl(); |
48
|
|
|
if (url.startsWith(base)) { |
49
|
|
|
return url.substr(base.length); |
50
|
|
|
} |
51
|
|
|
const basePath = basePathname(); |
52
|
|
|
if (url.startsWith(basePath)) { |
53
|
|
|
return url.substr(basePath.length); |
54
|
|
|
} |
55
|
|
|
return url; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
export function jobShow(locale: string, jobId: number): string { |
59
|
|
|
return `${baseUrl()}/${locale}/jobs/${jobId}`; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
function applicationShow( |
63
|
|
|
locale: string, |
64
|
|
|
prefix: string, |
65
|
|
|
applicationId: number, |
66
|
|
|
jobId: number, |
67
|
|
|
): string { |
68
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applications/${applicationId}`; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function applicantShow( |
72
|
|
|
locale: string, |
73
|
|
|
prefix: string, |
74
|
|
|
applicantId: number, |
75
|
|
|
jobId: number, |
76
|
|
|
): string { |
77
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applicants/${applicantId}`; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
export function managerApplicationShow( |
81
|
|
|
locale: string, |
82
|
|
|
applicationId: number, |
83
|
|
|
jobId: number, |
84
|
|
|
): string { |
85
|
|
|
return applicationShow(locale, "manager", applicationId, jobId); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
export function managerApplicantShow( |
89
|
|
|
locale: string, |
90
|
|
|
applicantId: number, |
91
|
|
|
jobId: number, |
92
|
|
|
): string { |
93
|
|
|
return applicantShow(locale, "manager", applicantId, jobId); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
export function managerEditProfile(locale: string): string { |
97
|
|
|
return `${baseUrl()}/${locale}/manager/profile`; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
export function managerJobIndex(locale: string): string { |
101
|
|
|
return `${baseUrl()}/${locale}/manager/jobs`; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
export function managerJobSummary(locale: string, jobId: number): string { |
105
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}`; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
export function managerJobPreview(locale: string, jobId: number): string { |
109
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/preview`; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
export function managerJobApplications(locale: string, jobId: number): string { |
113
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/applications`; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
export function managerScreeningPlan(locale: string, jobId: number): string { |
117
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/assessment-plan`; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
export function applicationReviewUpdate( |
121
|
|
|
locale: string, |
122
|
|
|
applicationId: number, |
123
|
|
|
): string { |
124
|
|
|
return `${baseApiUrl()}/applications/${applicationId}/review`; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
export function jobBuilderIntro(locale: string, jobId?: number): string { |
128
|
|
|
if (jobId) { |
129
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/intro`; |
130
|
|
|
} |
131
|
|
|
return `${baseUrl()}/${locale}/manager/job-builder/intro`; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
export function jobBuilderDetails(locale: string, jobId: number): string { |
135
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/details`; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
export function jobBuilderEnv(locale: string, jobId: number): string { |
139
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/environment`; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
export function jobBuilderImpact(locale: string, jobId: number): string { |
143
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/impact`; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
export function jobBuilderTasks(locale: string, jobId: number): string { |
147
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/tasks`; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
export function jobBuilderSkills(locale: string, jobId: number): string { |
151
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/skills`; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
export function jobBuilderReview(locale: string, jobId: number): string { |
155
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/review`; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
type FaqSection = "manager-who"; |
159
|
|
|
|
160
|
|
|
export function managerFaq(locale: string, faqSection?: FaqSection): string { |
161
|
|
|
const base = `${baseUrl()}/${locale}/manager/faq`; |
162
|
|
|
if (faqSection) { |
163
|
|
|
return `${base}#${faqSection}`; |
164
|
|
|
} |
165
|
|
|
return base; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
export function hrJobIndex(locale: string): string { |
169
|
|
|
return `${baseUrl()}/${locale}/hr/jobs`; |
170
|
|
|
} |
171
|
|
|
export function hrJobSummary(locale: string, jobId: number): string { |
172
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}`; |
173
|
|
|
} |
174
|
|
|
export function hrJobReview(locale: string, jobId: number): string { |
175
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/review`; |
176
|
|
|
} |
177
|
|
|
export function hrJobPreview(locale: string, jobId: number): string { |
178
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/preview`; |
179
|
|
|
} |
180
|
|
|
export function hrScreeningPlan(locale: string, jobId: number): string { |
181
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/assessment-plan`; |
182
|
|
|
} |
183
|
|
|
export function hrJobApplications(locale: string, jobId: number): string { |
184
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/applications`; |
185
|
|
|
} |
186
|
|
|
export const hrApplicationShow = ( |
187
|
|
|
locale: string, |
188
|
|
|
applicationId: number, |
189
|
|
|
jobId: number, |
190
|
|
|
): string => applicationShow(locale, "hr", applicationId, jobId); |
191
|
|
|
export const hrApplicantShow = ( |
192
|
|
|
locale: string, |
193
|
|
|
applicantId: number, |
194
|
|
|
jobId: number, |
195
|
|
|
): string => applicantShow(locale, "hr", applicantId, jobId); |
196
|
|
|
|
197
|
|
|
export function accountSettings(locale: string): string { |
198
|
|
|
return `${baseUrl()}/${locale}/settings`; |
199
|
|
|
} |
200
|
|
|
|